from __future__ import annotations

from typing import TYPE_CHECKING

from sqlalchemy import ForeignKey, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship

from app.db.base_class import BaseEntity

if TYPE_CHECKING:
  from .diary import DiaryEntry
  from .user import User


class DiaryComment(BaseEntity):
  __tablename__ = "diary_comments"

  diary_entry_id: Mapped[int] = mapped_column(ForeignKey("diary_entries.id", ondelete="CASCADE"), index=True)
  user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), index=True)
  content: Mapped[str] = mapped_column(Text)
  mood: Mapped[str | None] = mapped_column(String(64), nullable=True)

  diary_entry: Mapped["DiaryEntry"] = relationship(back_populates="comments", lazy="joined")
  user: Mapped["User"] = relationship("User", lazy="joined")
